import { createStore, combineReducers, applyMiddleware } from "redux";
import { persistStore, persistReducer } from "redux-persist";
import storage from "redux-persist/lib/storage"; // defaults to localStorage for web
import thunk from "redux-thunk";
import { composeWithDevTools } from "redux-devtools-extension";

import login from "store/login/reducer";
import register from "store/register/reducer";
import modifyPassword from "store/modify-password/reducer";
import app from "store/app/reducer";
import promotionPositionList from "store/promotion-position-list/reducer";
import orderList from "store/order-list/reducer";
import addPromotionPosition from "store/add-promotion-position/reducer";
import withdrawList from "store/withdraw-list/reducer";
import errWithdrawList from "store/err-withdraw-list/reducer";

const persistConfig = {
  key: "root",
  storage
};
const persistedReducer = persistReducer(
  persistConfig,
  combineReducers({
    login,
    register,
    modifyPassword,
    app,
    promotionPositionList,
    orderList,
    addPromotionPosition,
    withdrawList,
    errWithdrawList
  })
);

let store = createStore(
  persistedReducer,
  composeWithDevTools(applyMiddleware(thunk))
);
let persistor = persistStore(store);

export { store, persistor };

// let store = createStore(
//   combineReducers({
//     userList,
//     login,
//     register,
//     modifyPassword,
//     app,
//     promotionPositionList,
//     orderList,
//     addPromotionPosition
//   }),
//   composeWithDevTools(applyMiddleware(thunk))
// );

// export default store;
